/***********************************************
 This file is part of redia-bapps-main-ios.
 
 Copyright (c) 2015 Redia A/S
 
 Redia-bapps-main-ios is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 Redia-bapps-main-ios is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with redia-bapps-main-ios.  If not, see <http://www.gnu.org/licenses/>.
 
 *********************************************** */

//
//  BAColorChangingButton.m
//  redia-bapps-ios
//
//  Created by Nikolaj Tørring on 12/02/14.
//  Copyright (c) 2014 redia. All rights reserved.
//

#import "BAColorChangingButton.h"

@implementation BAColorChangingButton

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

-(void)awakeFromNib{
    if (self.normalColor == nil) {
        self.normalColor = self.backgroundColor;
    }
    
    if (self.highlightColor == nil) {
        self.highlightColor = self.normalColor;
    }
    
    if (self.selectedColor == nil) {
        self.selectedColor = self.normalColor;
    }
}

-(void)setHighlighted:(BOOL)highlighted{
    [super setHighlighted:highlighted];
    if (highlighted) {
        self.backgroundColor = self.highlightColor;
    }
    else if (self.selected) {
        self.backgroundColor = self.selectedColor;
    }
    else{
        self.backgroundColor = self.normalColor;
    }
}

-(void)setSelected:(BOOL)selected{
    [super setSelected:selected];
    if (selected) {
        self.backgroundColor = self.selectedColor;
    }
    else{
        self.backgroundColor = self.normalColor;
    }
}

@end
